using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using NorthStar.Passenger.Application.Responses;
using RestSharp;
using TheNorthStar.Api.Requests;
using TheNorthStar.Api.Results;


namespace NorthStar.Passenger.Application
{
    public class ApiService
    {
        private RestClient _client;
        public ApiService(string server)
        {
            _client = new RestClient(server);
        }
		public string ConvertAddressToGps(string address)
		{
			RestClient google = new RestClient("http://maps.google.com/maps/api/geocode/");
			
			 var request = new RestRequest("json?address={a}&sensor=true");
			request.AddUrlSegment("a", address);
			
            request.RequestFormat = DataFormat.Json;
            RestResponse response = google.Execute(request);
            return response.Content;
			
		}
        public string MakeBooking(NewBooking booking)
        {
            var request = new RestRequest("bookings", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(booking);

            RestResponse response = _client.Execute(request);
            //Booking res = Newtonsoft.Json.JsonConvert.DeserializeObject<Booking>(response.Content);
            return response.Content;
        }
        public string CancelBooking(CancelBookingRequest cancelBooking)
        {
            var request = new RestRequest("bookings/{id}",Method.PUT);
            request.AddObject(cancelBooking);
            request.RequestFormat = DataFormat.Json;
            RestResponse response = _client.Execute(request);
            return response.Content;
        }

        //maybe needs to be renamed to updateDriver??? since so similar to cancelbooking?
        public string RateDriver(RateDriverRequest rateDriver)
        {
            var request = new RestRequest("bookings/{id}", Method.PUT);
            request.AddObject(rateDriver);
            request.RequestFormat = DataFormat.Json;
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string GetBooking(int refId)
        {
            var request = new RestRequest("bookings/{id}");
            request.AddUrlSegment("id", refId.ToString());
            request.RequestFormat = DataFormat.Json;
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
    }
}